<!-- 我的论文隐匿名评审 -->
<template>
    <div>
        <div class="con color" >
            <el-row class="con_title">
              <el-col :span="6">
                <h2 class="text-style" >{{$t('paperBlindTrial.blindPaperApplyTitle')}}</h2>
                <div class="sub-text">
                  <span>{{$t('label.stuName')}}：{{global.currentUser.name}}</span>
                  <span style="margin-left: 20px;">{{$t('label.stuCode')}}：{{global.currentUser.uid}}</span>
                </div>
              </el-col>
              <el-col :span="16">
                <el-col :span="3" class="title-left">
                  <div class="text-style">{{$t('paperBlindTrial.isDraw')}}</div>
                  <div class="left-sub" style="font-size: 25px;color: red;">{{fieldChange(options.selectedFlag, thesisConcealEvaGrade.selectedFlag)}}</div>
                </el-col>
                <el-col :span="3" class="title-left">
                  <div class="text-style">{{$t('paperBlindTrial.havSendNum')}}</div>
                  <div class="left-sub" style="font-size: 25px;">{{thesisConcealEvaGrade.evaCount}}</div>
                </el-col>
                <el-col :span="3" class="title-left">
                  <div class="text-style">{{$t('paperBlindTrial.havSendArticles')}}</div>
                  <div class="left-sub" style="font-size: 25px;">{{thesisConcealEvaGrade.evaThesisCount}}</div>
                </el-col>
                <el-col :span="3" class="title-left">
                  <div class="text-style">{{$t('paperBlindTrial.hasPassNum')}}</div>
                  <div class="left-sub" style="font-size: 25px;">{{thesisConcealEvaGrade.passThesisCount}}</div>
                </el-col>
                <el-col :span="3" class="title-left">
                  <div class="text-style">{{$t('paperBlindTrial.finallyResult')}}</div>
                  <div class="left-sub" :style="thesisConcealEvaGrade.finalResult==='COMPLETE'?'font-size: 25px;color: #67c23a;':'font-size: 25px;'">{{fieldChange(options.finalResultArr, thesisConcealEvaGrade.finalResult)}}</div>
                </el-col>
              </el-col>
            </el-row>
            <div class="con_content">
                <el-button class="con_apply btn_top" type="primary" @click="applyState">{{$t('message.apply')}}</el-button>
                <edu-table ref="tables" :data="data" :selection="false" :total="total" @page-change="pageChange">
                    <el-table-column :min-width="item.width" v-for="item in label" :key="item.props" :label="item.label" :prop="item.props" show-overflow-tooltip></el-table-column>
                    <el-table-column min-width="100" :label="$t('courseSummary.aduitType')" prop="status" show-overflow-tooltip>
                      <template slot-scope="scope">
                        <el-tag v-show="scope.row.status"
                          :type="getType(scope.row.status)"
                        >{{ fieldChange(options.applyStatus, scope.row.status) }}</el-tag>
                      </template>
                    </el-table-column>
                    <el-table-column min-width="100" :label="$t('paperBlindTrial.sendArticlesLabel')" prop="evaExpertCount" show-overflow-tooltip>
                      <template slot-scope="scope">
                        {{scope.row.evaStatus==='N'?'':scope.row.evaExpertCount}}
                      </template>
                    </el-table-column>
                    <el-table-column min-width="80" :label="$t('paperBlindTrial.sendCount')" prop="evaCount" show-overflow-tooltip>
                      <template slot-scope="scope">
                        {{scope.row.evaCount==0?'':scope.row.evaCount}}
                      </template>
                    </el-table-column>
                    <el-table-column min-width="80" :label="$t('paperBlindTrial.sendStatus')" prop="evaStatus" show-overflow-tooltip>
                      <template slot-scope="scope">
                        {{ fieldChange(options.evaStatus, scope.row.evaStatus)}}
                      </template>
                    </el-table-column>
                    <!-- <el-table-column min-width="100" :label="$t('paperBlindTrial.assessResult')" prop="finalResult" show-overflow-tooltip>
                      <template slot-scope="scope">
                        {{ fieldChange(options.finalResultArr, scope.row.finalResult)}}
                      </template>
                    </el-table-column> -->
                    <!-- <el-table-column min-width="100" :label="$t('paperBlindTrial.isDraw')" prop="selectedFlag" show-overflow-tooltip>
                      <template slot-scope="scope">
                        {{ fieldChange(options.selectedFlag, scope.row.selectedFlag)}}
                      </template>
                    </el-table-column> -->
                    <el-table-column width="180px" :label="$t('nonPublicCourseOpen.operation')" fixed="right">
                        <template slot-scope="scope">
                            <div class="ReworkMana_btns" >
                              <el-button type="text" @click="add(scope.row, 'viewDetail')">{{$t('message.Look')}}</el-button>
                              <!-- 导师打回的时候可以编辑，送审之后不能编辑 -->
                              <el-button type="text" v-if="scope.row.status==='REJECT' && scope.row.evaStatus === 'N'" @click="add(scope.row, 'edit' )">{{$t('common.btn.edit')}}</el-button>
                              <el-button type="text" v-if="scope.row.selectedFlag === 'UNBLIND' && scope.row.status==='TUTOR_PASS'" @click="manualRateFunc(scope.row)">{{$t('paperBlindTrial.blindDraw')}}</el-button>
                              <el-button type="text" v-if="scope.row.evaStatus==='Y'" @click="add(scope.row, 'detail')">{{$t('paperBlindTrial.reviewDetail')}}</el-button>
                            </div>
                        </template>
                    </el-table-column>
                </edu-table>
            </div>

        </div>
        <!-- 申请/查看评审详情 -->
        <el-dialog :visible.sync="dialogFlag" :title="titles" width="800px">
            <reviewDetails v-if="dialogFlag && dialogType === 'detail'" :row="rows" ref="reviewDetails" @emit:back="backFunc" type="apply"></reviewDetails>
            <paperHiddenApply v-if="dialogFlag && (dialogType === 'edit' || dialogType === 'apply')" :yearTerms="yearTerms" :row="rows" ref="paperHiddenApply" @emit:back="backFunc"></paperHiddenApply>
            <viewDetail v-if="dialogFlag && dialogType === 'viewDetail'" :yearTerms="yearTerms" :row="rows" ref="viewDetail" @emit:back="backFunc"></viewDetail>
            <span slot="footer" class="dialog-footer">
              <span v-if="dialogType === 'edit' || dialogType === 'apply'">
                <el-button @click="dialogFlag = false">{{$t('message.cancel')}}</el-button>
                <el-button type="primary" @click="sure">{{$t('message.confirm')}}</el-button>
              </span>
              <el-button v-else @click="dialogFlag = false">{{$t('common.btn.close')}}</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import { applyTableList, applyManualRate } from "common/src/api/paperBlindTrial";
import calendars from 'common/src/api/calendars'
import paperHiddenApply from './paperHiddenApply';
import reviewDetails from './reviewDetails';
import viewDetail from './viewDetail';
import commonMixins from 'common/src/views/practiceManagement/commonMixins';
import mixin from 'common/src/mixins/index';
export default {
    components: {
        paperHiddenApply,
        reviewDetails,
        viewDetail
    },
    mixins: [commonMixins,mixin],
    props: {},
    data() {
        return {
            dialogFlag: false,
            rows: {},
            titles: this.$t('message.apply'),
            label: [
              { label: this.$t('label.schoolTerm'), props: 'yearTermI18n', width: 170 },
              { label: this.$t('achievementApply.thesisTitle'), props: 'thesisTitle', width: 150 },
              { label: this.$t('achievementApply.teacherName'), props: 'stuTutorName', width: 100 },
              { label: this.$t('paperBlindTrial.applyBatch'), props: 'batchNo', width: 100 },
              { label: this.$t('paperBlindTrial.applicantTime'), props: 'createTime', width: 155 }
            ],
            data: [],
            page: {
              pageNum_: 1,
              pageSize_: 20
            },
            total: 0,
            options: {
              applyStatus: [
                { label: this.$t('paperBlindTrial.tutorSubmit'), value: 'TUTOR_SUBMIT', type: '' },
                { label: this.$t('paperBlindTrial.blindSubmit'), value: 'BLIND_SUBMIT', type: '' },
                { label: this.$t('paperBlindTrial.tutorPass'), value: 'TUTOR_PASS', type: 'success' },
                { label: this.$t('paperBlindTrial.agreeLabel'), value: 'PASS', type: 'success' },
                { label: this.$t('achievementApply.refuse'), value: 'REJECT', type: 'danger' },
              ],
              finalResultArr: [
                { label: this.$t('message.pass'), value: 'COMPLETE', type: 'success' },
                // { label: this.$t('paperBlindTrial.finished'), value: 'COMPLETE', type: 'success' },
                { label: this.$t('achievementApply.unfinished'), value: 'INCOMPLETE', type: 'danger' },
              ],
              evaStatus: [
                { label: this.$t('paperBlindTrial.hasSend'), value: 'Y', type: 'success' },
                { label: this.$t('paperBlindTrial.notSend'), value: 'N', type: 'warning' }
              ],
              selectedFlag: [
                { label: this.$t('paperBlindTrial.notDrawn'), value: 'UNBLIND', type: '' }, // 未抽盲
                { label: this.$t('paperBlindTrial.drawn'), value: 'Y', type: 'success' }, // 抽中
                { label: this.$t('paperBlindTrial.missed'), value: 'N', type: 'warning' } // 未中
              ],
            },
            thesisConcealEvaGrade: {}, // 标题部分数据
            yearTerms: {},
            dialogType: '',
        };
    },
    computed: {

    },
    created() {
    },
    mounted() {
      this.getYearTeam();
      this.getLists();
    },
    methods: {
        // 获取学年
        getYearTeam () {
          calendars.listAllCalendar()
          .then(res => {
            if (res.code === 200) {
              let currentYear = res.data.filter(v => v.currentTermFlag)[0];
              this.yearTerms = currentYear?currentYear:{};
            }
          });
        },
        pageChange(val) { // 分页切换功能
          [this.page.pageNum_, this.page.pageSize_] = [val.pageNum, val.pageSize];
          this.getLists();
        },
        getLists() {  // 获取列表
          let params = {
            ...this.page,
            condition: {}
          };
          applyTableList(params)
            .then(response => {
              if (response.code === 200) {
                this.thesisConcealEvaGrade = response.data.thesisConcealEvaGradeT || {};
                this.data = response.data.pageResult.list;
                this.total = response.data.pageResult.total_;
              } else throw response.code;
            });
        },
        add(val, type) { // 申请/详情
          if (type === 'apply') {
            this.titles = this.$t('message.apply');
          } else if (type === 'edit') {
            this.titles = this.$t('common.btn.edit');
          } else if (type === 'detail') {
            this.titles = this.$t('paperBlindTrial.reviewDetail');
          } else if (type === 'viewDetail') {
            this.titles = this.$t('message.Look');
          }
          this.rows = _.cloneDeep(val);
          this.dialogType = type;
          this.dialogFlag = true;
        },
        sure() { // 申请确定
          if (this.rows.applyId) {
            this.$refs.paperHiddenApply.save('edit');
            return;
          }
          this.$refs.paperHiddenApply.save();
        },
        backFunc () {
          this.dialogFlag = false;
          this.getLists();
        },
        getType(val) {
          let option = this.options.applyStatus.find(v => v.value == val);
          return option ? option.type : null
        },
        // 盲抽方法
        manualRateFunc (row) {
          applyManualRate(row.applyId).then(res=>{
            if (res.code === 200) {
              this.$message.success(res.msg);
              this.getLists();
            }
          });
        },
        // 申请按钮点击根据页面数据提示是否可以申请
        applyState() {
          let sendData = this.data.filter(v=>v.evaStatus === 'Y').length; // 过滤已送审数据
          let passData = this.data.filter(v=>v.status === 'PASS').length; // 过滤通过的数据
          let tutorPassData = this.data.filter(v=>v.status === 'TUTOR_PASS').length; // 过滤导师审批通过的数据
          let tableNum = this.data.length; // 表格数据长度
          let selectedFlag = this.thesisConcealEvaGrade.selectedFlag === 'Y'; // 是否抽中
          if (this.thesisConcealEvaGrade.finalResult === 'COMPLETE') {
            this.$message.error(this.$t('paperBlindTrial.finishApplyTips'));
            return;
          }
          // 有申请数据，未抽盲且导师审核完成
          if (tableNum > 0 && !this.thesisConcealEvaGrade.selectedFlag && tutorPassData === tableNum) {
            this.$message.error(this.$t('paperBlindTrial.selectTips'));
            return;
          }
          // 抽中且存在未送审的数据
          if (tableNum > 0 && selectedFlag && sendData !== tableNum) {
            this.$message.error(this.$t('paperBlindTrial.applyTips'));
            return;
          }
          // 未抽中审核通过的数据不等于表格数据
          if (tableNum > 0 && !selectedFlag && passData !== tableNum) {
            this.$message.error(this.$t('paperBlindTrial.applyTips'));
            return;
          }
          this.add({}, 'apply'); // 提交申请
        }
    }
};
</script>

<style scoped lang="scss">
.con {
    &_content {
        display: flex;
        flex-direction: column;
    }
    &_apply {
        align-self: flex-end;
        margin-bottom: 10px;
    }
    &_status {
        border-bottom: solid #ccc 1px;
        display: block;
        padding: 5px 0;
        margin-bottom: 10px;
    }
    &_title {
      width: 100%;
      border-bottom: solid #ccc 2px;
      padding: 20px;
    }
}
.color {
  background-color: white;
}
.text-style {
  color: #2B3B4E;
}
.sub-text {
  color: #8896A7;
}
.title-left {
  text-align: center;
}
.left-sub {
  margin-top: 5px;
  font-size: 20px;
  font-weight: bold;
  color: #2B3B4E;
}
.btn_top {
  margin-top: 10px;
}
</style>
